import whisper
import zhconv
import time
def w2s(file_path):
    start_time = time.time()

    model = whisper.load_model("tiny")#可选模型：tiny、base、small、medium、large 越小速度越快，但准确率下降
    # record(5)  # 定义录音时间，单位/s
    result = model.transcribe(audio=file_path, language='Chinese', fp16=False)
    s = result["text"]
    # print(s)
    s1 = zhconv.convert(s, 'zh-cn')
    end_time = time.time()
    print(s1)
    print("语音识别用时：", end_time - start_time, "秒")
    return s1


if __name__ == '__main__':
    #调用函数
    w2s("../test.wav")